import cgi
import os
from google.appengine.ext import db
from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app


class Auto(db.Model):
  marca = db.StringProperty()
  modelo = db.StringProperty()
  anio = db.IntegerProperty()
  cilindrada=db.StringProperty()
  tipo=db.StringProperty()

class MainPage(webapp.RequestHandler):
  def get(self): 	
    path=os.path.join(os.path.dirname(__file__), 'create.htm')
    self.response.out.write(template.render(path, None))

class New(webapp.RequestHandler):
  def post(self): 
    auto=Auto()
    auto.marca=self.request.get('txtMarca')
    auto.modelo=self.request.get('txtModelo')
    auto.anio=int(self.request.get('txtAnio'))
    auto.tipo=self.request.get('selTipo')
    auto.cilindrada=self.request.get('txtCilindrada')
    
    auto.put()
    
    self.response.out.write('se ha guardado correctamente')

class Ver(webapp.RequestHandler):
  def get(self): 
    autos=Auto.all()
    
    template_values = {
       'autos': autos,
       }
       
    path=os.path.join(os.path.dirname(__file__), 'ver.htm')
    self.response.out.write(template.render(path, template_values))
        


application = webapp.WSGIApplication(
                                     [('/', MainPage),
                                      ('/new', New),
                                      ('/ver',Ver),],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()